package com.zhj.process.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhj.process.entity.converter.ModelConverter;
import com.zhj.process.entity.dto.ModelDTO;
import com.zhj.process.entity.po.Model;
import com.zhj.process.entity.req.ModelReq;
import com.zhj.process.mapper.ModelMapper;
import com.zhj.process.service.ModelService;

import org.springframework.stereotype.Service;

import java.util.List;

import lombok.AllArgsConstructor;


/**
 * 流程模型信息表(Model)表服务实现类
 *
 * @author zhonghaijun
 * @since 2023-07-06 11:36:30
 */
@Service
@AllArgsConstructor
public class ModelServiceImpl implements ModelService {
    /**
     * 通过构造函数自动注入
     */
    private final ModelMapper modelMapper;

    /**
     * Gets by id *
     *
     * @param id id
     * @return the by id
     * @since 1.0.0
     */
    @Override
    public ModelDTO getById(Long id) {
        return ModelConverter.INSTANCE.poToDto(this.modelMapper.selectById(id));
    }

    /**
     * Gets all *
     *
     * @return the all
     * @since 1.0.0
     */
    @Override
    public List<ModelDTO> getAll() {
        return ModelConverter.INSTANCE.poToDto(this.modelMapper.selectList(null));
    }

    /**
     * Save
     *
     * @param modelReq modelReq
     * @return the boolean
     * @since 1.0.0
     */
    @Override
    public boolean save(ModelReq modelReq) {
        return this.modelMapper.insert(ModelConverter.INSTANCE.reqToPo(modelReq)) > 0;
    }

    /**
     * Update by id
     *
     * @param modelReq modelReq
     * @return the boolean
     * @since 1.0.0
     */
    @Override
    public boolean updateById(ModelReq modelReq) {
        return this.modelMapper.updateById(ModelConverter.INSTANCE.reqToPo(modelReq)) > 0;
    }

    /**
     * Delete by id
     *
     * @param id id
     * @return the boolean
     * @since 1.0.0
     */
    @Override
    public boolean deleteById(Long id) {
        return this.modelMapper.deleteById(id) > 0;
    }

    /**
     * 分页查询
     *
     * @param page page
     * @return IPage<ModelDTO> page
     */
    @Override
    public IPage<ModelDTO> getPage(IPage<Model> page) {
        return ModelConverter.INSTANCE.poToDto(this.modelMapper.selectPage(page, null));
    }
}

